package com.example.demo.module.develop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.service.impl.BaseServiceImpl;
import com.example.demo.entity.pojo.develop.DevelopBomMaterielPoJo;
import com.example.demo.entity.request.develop.DevelopBomMaterielRequest;
import com.example.demo.module.develop.mapper.DevelopBomMaterielMapper;
import com.example.demo.module.develop.service.DevelopBomMaterielService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


@Service("developBomMaterielService")
public class DevelopBomMaterielServiceImpl extends BaseServiceImpl<DevelopBomMaterielMapper, DevelopBomMaterielPoJo> implements DevelopBomMaterielService {
    @Resource
    private DevelopBomMaterielMapper mapper;

    private LambdaQueryWrapper<DevelopBomMaterielPoJo> getLambda(DevelopBomMaterielPoJo poJo) {
        Long id = poJo.getId();
        Long bomId = poJo.getBomId();
        Long companyId = poJo.getCompanyId();
        Date createTime = poJo.getCreateTime();
        Date updateTime = poJo.getUpdateTime();
        Boolean isDelete = poJo.getIsDelete();
        String companyName = poJo.getCompanyName();
        String num = poJo.getNum();
        String name = poJo.getName();
        String spec = poJo.getSpec();
        Integer quantity = poJo.getQuantity();
        String position = poJo.getPosition();
        String remarks = poJo.getRemarks();
        Long repositoryId = poJo.getRepositoryId();

        LambdaQueryWrapper<DevelopBomMaterielPoJo> wrapper = new LambdaQueryWrapper<DevelopBomMaterielPoJo>();
        wrapper
                .eq(id != null, DevelopBomMaterielPoJo::getId, poJo.getId())
                .eq(companyId != null, DevelopBomMaterielPoJo::getCompanyId, poJo.getCompanyId())
                .eq(createTime != null, DevelopBomMaterielPoJo::getCreateTime, poJo.getCreateTime())
                .eq(updateTime != null, DevelopBomMaterielPoJo::getUpdateTime, poJo.getUpdateTime())
                .eq(isDelete != null, DevelopBomMaterielPoJo::getIsDelete, poJo.getIsDelete())
                .eq(companyName != null, DevelopBomMaterielPoJo::getCompanyName, poJo.getCompanyName())
                .like(name != null, DevelopBomMaterielPoJo::getName, poJo.getName())
                .eq(spec != null, DevelopBomMaterielPoJo::getSpec, poJo.getSpec())
                .eq(bomId != null, DevelopBomMaterielPoJo::getBomId, poJo.getBomId())
                .eq(num != null, DevelopBomMaterielPoJo::getNum, poJo.getNum())
                .eq(quantity != null, DevelopBomMaterielPoJo::getQuantity, poJo.getQuantity())
                .eq(position != null, DevelopBomMaterielPoJo::getPosition, poJo.getPosition())
                .eq(remarks != null, DevelopBomMaterielPoJo::getRemarks, poJo.getRemarks())
                .eq(repositoryId != null, DevelopBomMaterielPoJo::getRepositoryId, poJo.getRepositoryId());
        return wrapper;
    }

    @Override
    public List<DevelopBomMaterielPoJo> findList(DevelopBomMaterielPoJo poJo) {
        return mapper.selectList(getLambda(poJo));
    }

    @Override
    public Page<DevelopBomMaterielPoJo> findPage(DevelopBomMaterielRequest request) {
        DevelopBomMaterielPoJo poJo = new DevelopBomMaterielPoJo();
        BeanUtils.copyProperties(request, poJo);
        return mapper.selectPage(new Page<>(request.getPage(), request.getSize()), getLambda(poJo));
    }

    @Override
    public void batchRemove(List<Long> ids) {
        if (ids.size() != 0) {
            mapper.deleteBatchIds(ids);
        }

    }


}